import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import store from "@/store"


const routes: Array<RouteRecordRaw> = [
  //  首页
  {
    path: "/",
    name: "index",
    redirect: "/control"
  },
  // 登录
  {
    path: "/login",
    name: "login",
    component: ()=>import("@/views/login/TestLogin.vue"),
  },
  //  施工管控
  {
    path: "/control",
    name: "control",
    redirect: "/control/analyse/data",
    component: ()=>import("@/views/control/Control.vue"),
    children: [
      // 统计
      {
        path: "/control/analyse/data",
        name: "analyse-data",
        component: ()=>import("@/views/control/analyse/Data.vue"),
        meta: {
          requireAuth: true,
        }
      },
      //  碾压
      {
        path: "/control/compaction/monitor",
        name: "compaction-monitor",
        component: ()=>import("@/views/control/compaction/Monitor.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/compaction/report",
        name: "compaction-report",
        component: ()=>import("@/views/control/compaction/Report.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/compaction/task",
        name: "compaction-task",
        component: ()=>import("@/views/control/compaction/Task.vue"),
        meta: {
          requireAuth: true,
        }
      },
      // 强夯
      {
        path: "/control/tamp/monitor",
        name: "tamp-monitor",
        component: ()=>import("@/views/control/tamp/Monitor.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/tamp/report",
        name: "tamp-report",
        component: ()=>import("@/views/control/tamp/Report.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/tamp/task",
        name: "tamp-task",
        component: ()=>import("@/views/control/tamp/Task.vue"),
        meta: {
          requireAuth: true,
        }
      },
      //  摊铺
      {
        path: "/control/paver/monitor",
        name: "paver-monitor",
        component: ()=>import("@/views/control/paver/Monitor.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/paver/report",
        name: "paver-report",
        component: ()=>import("@/views/control/paver/Report.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/paver/task",
        name: "paver-task",
        component: ()=>import("@/views/control/paver/Task.vue"),
        meta: {
          requireAuth: true,
        }
      },
      // CFG
      {
        path: "/control/cfg/monitor",
        name: "cfg-monitor",
        component: ()=>import("@/views/control/cfg/Monitor.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/cfg/report",
        name: "cfg-report",
        component: ()=>import("@/views/control/cfg/Report.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/cfg/task",
        name: "cfg-task",
        component: ()=>import("@/views/control/cfg/Task.vue"),
        meta: {
          requireAuth: true,
        }
      },
      // 拌合站
      {
        path: "/control/mix/collect",
        name: "mix-monitor",
        component: ()=>import("@/views/control/mix/collect.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/mix/data",
        name: "mix-report",
        component: ()=>import("@/views/control/mix/data.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/mix/setting",
        name: "mix-task",
        component: ()=>import("@/views/control/mix/setting.vue"),
        meta: {
          requireAuth: true,
        }
      },
      // 旋挖钻
      {
        path: "/control/rotary/monitor",
        name: "rotary-monitor",
        component: ()=>import("@/views/control/rotary/Monitor.vue"),
        meta: {
            requireAuth: true,
        }
      },
      {
        path: "/control/rotary/report",
        name: "rotary-report",
        component: ()=>import("@/views/control/rotary/Report.vue"),
        meta: {
            requireAuth: true,
        }
      },
      {
        path: "/control/rotary/task",
        name: "rotary-task",
        component: ()=>import("@/views/control/rotary/Task.vue"),
        meta: {
            requireAuth: true,
        }
      },
      // 水泥搅拌
      {
        path: "/control/cement/monitor",
        name: "cement-monitor",
        component: ()=>import("@/views/control/cement/Monitor.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/cement/report",
        name: "cement-report",
        component: ()=>import("@/views/control/cement/Report.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/cement/task",
        name: "cement-task",
        component: ()=>import("@/views/control/cement/Task.vue"),
        meta: {
          requireAuth: true,
        }
      },
      // 能耗监测
      {
        path: "/control/energy/survey",
        name: "energy-survey",
        component: ()=>import("@/views/control/energy/Survey.vue"),
        meta: {
          requireAuth: true,
        }
      },
      // 洒水车
      {
        path: "/control/water/monitor",
        name: "water-monitor",
        component: ()=>import("@/views/control/water/Monitor.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/water/data",
        name: "water-data",
        component: ()=>import("@/views/control/water/Data.vue"),
        meta: {
          requireAuth: true,
        }
      },
      // 其他设置
      {
        path: "/control/manager/cell",
        name: "manager-cell",
        component: ()=>import("@/views/control/manager/Cell.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/manager/device",
        name: "manager-device",
        component: ()=>import("@/views/control/manager/Device.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/manager/vehicle",
        name: "manager-vehicle",
        component: ()=>import("@/views/control/manager/Vehicle.vue"),
        meta: {
          requireAuth: true,
        }
      },
      //车辆管理
      {
        path: "/control/vehicle/monitor",
        name: "vehicle-monitor",
        component: ()=>import("@/views/control/vehicle/Monitor.vue"),
        meta: {
          requireAuth: true,
        }
      },
      //环境监控dataquery.vue
      {
        path: "/control/datanalysis/analysis",
        name: "datanalysis-huanj",
        component: ()=>import("@/views/control/datanalysis/analysis.vue"),
        meta: {
          requireAuth: true,
        }
      },
      {
        path: "/control/datanalysis/dataquery",
        name: "datanalysis-shuf",
        component: ()=>import("@/views/control/datanalysis/dataquery.vue"),
        meta: {
          requireAuth: true,
        }
      },
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next)=>{
  if (to.meta.requireAuth) {
    if (store.getters["userinfo/getUserInfo"].token) {
      next();
    }
    else {
      next({
        path: '/login',
        query: {redirect: to.fullPath}
      })
    }
  }
  else {
    next();
  }
})

export default router;
